package jbpmguice.instantiation;

import org.jbpm.instantiation.ConfigurationPropertyInstantiator;

/**
 * This Instantiator loads the GuiceFieldInstantiator.GuiceFieldInstantiator configuration and instantiates new objects.
 * <p/>
 * User: goettl
 * Date: 11.02.11
 * Time: 10:30
 */
public class GuiceConfigurationPropertyInstantiator extends ConfigurationPropertyInstantiator {
    String configType = "configuration-property";


    @SuppressWarnings({"rawtypes", "unchecked"})
    protected Object newInstance(Class clazz) {
        return GuiceConfigurationLoader.getConfigurationLoader().getInstance(clazz);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        GuiceConfigurationPropertyInstantiator that = (GuiceConfigurationPropertyInstantiator) o;

        if (configType != null ? !configType.equals(that.configType) : that.configType != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return configType != null ? configType.hashCode() : 0;
    }
}
